package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(MinioProperties.class)
//@ConfigurationPropertiesScan(basePackages = "com.atguigu.lease.common.minio")
@ConditionalOnProperty(prefix = "minio",value = {"endpoint","access-key","secret-key"})
public class MinioConfiguration {
    @Autowired
    private MinioProperties MinioProperties;
    @Bean
    public MinioClient minioClientFactory() {
        return MinioClient.builder()
                .endpoint(MinioProperties.getEndpoint())
                .credentials(MinioProperties.getAccessKey(), MinioProperties.getSecretKey())
                .build();
    }
}
